package com.invengo.module_check.ui.fragment.first_check;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.invengo.library_db.entity.module_check.RecordBean;
import com.invengo.module_check.BR;
import com.invengo.module_check.R;
import com.invengo.module_check.data.repsitory.business.BusinessRepsitory;
import com.invengo.module_check.ui.fragment.bookdown.fragment.item.BookDownByBookItemViewModel;
import com.invengo.module_check.ui.fragment.first_check.item.PosRecordItemViewModel;

import java.util.List;

import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class FirstRecordViewModel extends BaseViewModel<BusinessRepsitory> {
    public SingleLiveEvent<Integer> recordCount = new SingleLiveEvent<>();
    public ObservableList<PosRecordItemViewModel> recordItemList = new ObservableArrayList<>();
    public ItemBinding<PosRecordItemViewModel> recordItemBinding = ItemBinding.of(BR.viewModel, R.layout.item_pos_record);

    public FirstRecordViewModel(@NonNull Application application) {
        super(application, BusinessRepsitory.getInstance());
    }

    private int status = 2;
    public static final int PAGE_SIZE = 1220;
    private int pageIndex = 1;

    public void getRecordList() {
        model.getUpdateRecordList(status, pageIndex, PAGE_SIZE)
                .compose(RxUtils.applySchedulersLoading(getLifecycleProvider(), this))
                .subscribe(recordBean -> {
                    recordCount.postValue(recordBean.getTotalCount());
                    addItem(recordBean.getItems());
                });
    }

    private void addItem(List<RecordBean.ItemsDTO> beans) {
        for (RecordBean.ItemsDTO bean : beans) {
//            recordItemList.add(new PosRecordItemViewModel(this, bean));
        }
    }

    public int getPosition(ItemViewModel item) {
        return recordItemList.indexOf(item);
    }

}
